/**
 * 
 */
var url = "/tcjh/reportservlet";
var type = "1";
var column1 = "";
var column2 = "";
$(function(){
	if(type==1){
//		$("#column1").html("媒体来源");
//		$("#column2").html("点击次数");
		column1 = "媒体来源";
		column2 = "点击次数";
	} else if(type==2){
//		$("#column1").html("媒体来源");
//		$("#column2").html("点击次数");
		column1 = "媒体来源";
		column2 = "点击次数";
	} else if(type==3){
//		$("#column1").html("点击数");
//		$("#column2").html("参与数");
		column1 = "点击数";
		column2 = "参与数";
	} else if(type==4){
//		$("#column1").html("城市");
//		$("#column2").html("参与数");
		column1 = "城市";
		column2 = "参与数";
	}
	getReport(type);
});

function getReport(type)
{
	sendServer(url+"?type="+type,null,getReportResponse,"json");
}

//function getReportResponse(json)
//{
//	// 报表标题
//	$("#reportName").html(json.reportName);
//	
//	// 报表表格
//	var tbHtml = $("#tbData").html();
//	$.each(json.tableData, function(index, obj){
//		if(index%2) {
//			tbHtml = tbHtml +
//			"<tr>" +
//	        "<td class='tbContent1'>" + obj.name + "</td>" +
//	        "<td class='tbContent1'>" + obj.count + "</td>" +
//	      	"</tr>"
//		} else {
//			tbHtml = tbHtml +
//			"<tr>" +
//	        "<td class='tbContent2'>" + obj.name + "</td>" +
//	        "<td class='tbContent2'>" + obj.count + "</td>" +
//	      	"</tr>"
//		}
//			
//	});
//	$("#tbData").html(tbHtml);
//	
//	// 报表图表
//	$("#mediaChart").attr("src", json.chartView[0].chartTempPath);
//	var chartHtml = "";
//	$.each(json.chartView, function(index, obj){
//		if(index>0) {
//			chartHtml = chartHtml +
//				"<dt class='adpStaticsticPic' onmouseover='showin(this)' onmouseout='shouout(this)'>" +
//				"  <img width='300' height='200' src='" + obj.chartTempPath + "'/>" +
//				"</dt>"
//		}
//	});
//	$("#chartView").html(chartHtml);
//	
//}

var getReportResponse = function(data) {
	
	// 报表标题
	$("#reportName").html(data.reportName);
	
	var chartDataHtml = "";
	var buildPicLi = function(conf){
		var pHtml = 
				"<li>" +
				"  <a href='" + conf.href + "'>" +
				"    <img src='" + conf.src + "'" +
				"         title='" + conf.title + "'" +
				"         alt='" + conf.alt + "'" +
				"         class='" + conf.className + "'" +
				"    />" +
				"  </a>" +
				"</li>";
		return pHtml;
	};
	var buildAlt = function(data) {
		var altHtml = 
			"<table id=\"tbData\" class=\"tbData\">" +
			  "<tr>" +
			    "<td class=\"tbHead\">" + column1 + "</td>" +
			    "<td class=\"tbHead\">" + column2 + "</td>" +
			  "</tr>";
		$.each(data, function(index, obj){
			if(index%2 == 1) {
				altHtml = altHtml +
				"<tr>" +
		        "<td class=\"tbContent1\">" + obj.name + "</td>" +
		        "<td class=\"tbContent1\">" + obj.count + "</td>" +
		      	"</tr>"
			} else {
				altHtml = altHtml +
				"<tr>" +
		        "<td class=\"tbContent2\">" + obj.name + "</td>" +
		        "<td class=\"tbContent2\">" + obj.count + "</td>" +
		      	"</tr>"
			}
		});
		altHtml = altHtml + "</table>";
		return altHtml;
	};
//	chartDataHtml = chartDataHtml + buildPicLi({
//		href:data.cData.chartTempPath,
//		src:data.cData.chartTempPath,
//		title:"",//data.cData.chartName,
//		alt:buildAlt(data.tData),
//		className:"thumbPic"
//	});
	$.each(data.chartViewList, function(index, obj){
		chartDataHtml = chartDataHtml + buildPicLi({
			href:obj.chartTempPath,
			src:obj.chartTempPath,
			title:"",//obj.chartName,
			alt:buildAlt(data.tableDataList[index]),
			className:"thumbPic"
		});
	});
	$(".ad-thumb-list").html(chartDataHtml);
	$("#descriptions").html("");
	$(".ad-controls").html("");
	galleries = $('.ad-gallery').adGallery();
	galleries[0].settings.effect = "slide-vert"; // slide-hori,slide-vert,resize,fade
	galleries[0].slideshow.toggle();
	galleries[0].settings.description_wrapper = $("#descriptions");
}
